/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.dao.hibernate;

import com.minierp.dao.IdGenerator;
import com.minierp.model.IdObject;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class IdGeneratorImpl extends HibernateDaoSupport implements IdGenerator {
	public long getId(String name) {
		Class arg1 = IdGeneratorImpl.class;
		synchronized (IdGeneratorImpl.class) {
			HibernateTemplate ht = this.getHibernateTemplate();
			IdObject obj = (IdObject) ht.get(IdObject.class, name);
			long retVal;
			if (obj == null) {
				retVal = 1L;
				obj = new IdObject();
				obj.setName(name);
				obj.setValue(retVal);
				ht.save(obj);
			} else {
				retVal = obj.getValue() + 1L;
				obj.setValue(retVal);
				ht.update(obj);
			}

			return retVal;
		}
	}

	public long getId(String name, int num) {
		Class arg2 = IdGeneratorImpl.class;
		synchronized (IdGeneratorImpl.class) {
			HibernateTemplate ht = this.getHibernateTemplate();
			IdObject obj = (IdObject) ht.get(IdObject.class, name);
			long retVal;
			if (obj == null) {
				retVal = 1L;
				obj = new IdObject();
				obj.setName(name);
				obj.setValue((long) num);
				ht.save(obj);
			} else {
				retVal = obj.getValue() + 1L;
				obj.setValue(obj.getValue() + (long) num);
				ht.update(obj);
			}

			return retVal;
		}
	}
}